package net.yxsoft.controller.pc.sysmgt;


import com.jfinal.upload.UploadFile;
import net.yxsoft.controller.pc.sysmgt.common.AuthController;
import net.yxsoft.model.SLifecycModel;
import net.yxsoft.model.SLifecycModelNode;
import net.yxsoft.model.SLifecycModelNodeAcc;
import net.yxsoft.model.infrastructure.TsCode;
import net.yxsoft.model.infrastructure.TsMenu;
import net.yxsoft.service.LifecycleService;
import org.json.JSONArray;
import org.json.JSONObject;
import rapid.jfinal.Pagination;

import java.util.List;



/**
* @MethodName: 生命周期模型管理
* @Description:
* @param: null
* @return * @return null
* @throws
* @date 2023/8/31 13:44
* @author jhf
*/
public class LifecycleController extends AuthController {

  private static final LifecycleService ser = LifecycleService.INSTANCE;
  /**
  * @MethodName: index
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void index() {
    render("lifecycle.html");
  }

  /**
  * @MethodName: getLifecycModel
  * @Description: 获取生命周期模型列表
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void getLifecycModel(){
    renderJson(ser.getLifecycModel(getParamKeyMap()));
  }

  /**
  * @MethodName: getLifecycModelNode
  * @Description: 获取生命周期模型节点列表
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void getLifecycModelNode(){
    renderJson(ser.getLifecycModelNode(getParamKeyMap(), Pagination.by(this)));
  }

  /**
  * @MethodName: getLifecycAcc
  * @Description: 获取生命周期节点附件列表
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void getLifecycAcc(){
    renderJson(ser.getLifecycAcc(getParamKeyMap()));
  }
  /**
  * @MethodName: saveLifecycModel
  * @Description: 新增、修改生命周期模型
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void saveLifecycModel(){
    String pid = getPara("pid");
    Integer ismodel = 1;
    renderJson(ser.saveLifecycModel(getModel(SLifecycModel.class, "", true),pid,ismodel,getLoginUser()));
  }
  /**
  * @MethodName: deleteLifecycModel
  * @Description: 删除生命周期模型
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void deleteLifecycModel(){
    String _id = getPara("ids");
    String[] id_arr = _id.split(",");
    renderJson(ser.deleteLifecyc(id_arr,getLoginUser()));
  }
  /**
  * @MethodName: saveLifecycModelNode
  * @Description: 新增、修改生命周期模型节点
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void saveLifecycModelNode(){
    renderJson(ser.saveLiftcycModelNode(getModel(SLifecycModelNode.class, ""),getLoginUser()));
  }
  /**
  * @MethodName: deleteLifecycNode
  * @Description: 根据主键值删除生命周期模型节点
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:44
  * @author jhf
  */
  public void deleteLifecycNode(){
    String ids = getPara("ids");
    String[] _ids = ids.split(",");
    renderJson(ser.deleteLifecycNode(_ids));
  }

  /**
  * @MethodName: saveLifecycModelNodeAcc
  * @Description: 新增、修改生命周期模型节点附件
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void saveLifecycModelNodeAcc(){
    renderJson(ser.saveLifecycAcc(getModel(SLifecycModelNodeAcc.class,""),getLoginUser()));
  }

  /**
  * @MethodName: deleteLifecycAcc
  * @Description: 根据主键值删除生命周期模型节点附件
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void deleteLifecycAcc(){
    String _ids = getPara("ids");
    String[] _id_arr = _ids.split(",");
    renderJson(ser.deleteLifecycAcc(_id_arr));
  }
  /**
  * @MethodName: getFormName
  * @Description: 获取关联表单
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void getFormName(){
    String _serch = getPara("search_name");
    renderJson(ser.getForm(_serch));
  }
  /**
  * @MethodName: getFileType
  * @Description: 获取附件类型picker
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void getFileType(){
    renderJson(new TsCode().dao.find("select * from TS_CODE where CODETYPE = 'FJLX' and LEAF = '2'"));
  }
  /**
  * @MethodName: upload
  * @Description:
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void upload() {
    List<UploadFile> uploadFiles = getFiles();
    JSONObject json = new JSONObject();
    JSONArray arr = new JSONArray();
    for(UploadFile upload : uploadFiles) {
      arr.put("/files/" + upload.getFileName());
    }
    json.put("errno", 0);
    json.put("data", arr);
    renderText(json.toString());
  }

  /**
  * @MethodName: saveMenu
  * @Description: 保存生命周期菜单
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void saveMenu() {
    String exampleName = getPara("exampleName");
    String exampleCode = getPara("exampleCode");
    Integer ismodel = 1;
    renderJson(ser.saveMenu(getModel(TsMenu.class, "", true), exampleName, exampleCode,ismodel, getLoginUser()));
  }

  /**
  * @MethodName: getMenus
  * @Description: 获取生命周期菜单
  * @param:
  * @return void
  * @throws
  * @date 2023/8/31 13:45
  * @author jhf
  */
  public void getMenus(){
    renderJson(ser.getMenus());
  }


}
